using TMPro;
using UnityEngine;
using UnityEngine.UI;

public class HealthUI : MonoBehaviour
{
    public Slider healthSlider;
    public TextMeshProUGUI nameText;
    public PlayerController player;

    private Camera mainCamera;

    void Start()
    {
        mainCamera = Camera.main;
    }

    void Update()
    {
        if (player != null)
        {

            transform.position = player.transform.position;
            transform.rotation = mainCamera.transform.rotation;

            healthSlider.value = player.health / 100f;

            nameText.text = player.playerId;
        }
    }
    public void Refresh()
    {
        if (player != null && healthSlider != null)
        {
            healthSlider.value = player.health;
        }
    }
}